<?php echo $this->render('header.phtml'); ?>
<?php echo $this->render('menu.phtml'); ?>
<div id="content">
    <div id="icon-link" class="icon32"><br/></div><h2>链接分类</h2>
    <div id="tabs">
        <ul>
            <li><a href="#tabs-1">列表</a></li>
            <li><a href="#tabs-2">添加</a></li>
            <li><a href="#tabs-3">编辑</a></li>
        </ul>
        <div id="tabs-1">
            <table class="list-table">
                <thead class="ui-state-default">
                    <tr>
                        <th width="5%">ID</th>
                        <th width="20%">类型</th>
                        <th width="45%">描述</th>
                        <th width="15%">顺序</th>
                        <th width="15%">编辑</th>
                    </tr>
                </thead>
                <tbody>
                    <?php if (!empty($this->linkTypeList)) : ?>
                        <?php foreach ($this->linkTypeList as $linkType) : ?>
                    <tr>
                        <td><?php echo $this->escape($linkType->typeId) ?></td>
                        <td><?php echo $this->escape($linkType->typeName) ?></td>
                        <td><?php echo $this->escape($linkType->typeDesc) ?></td>
                        <td><?php echo $this->escape($linkType->displayOrder) ?></td>
                        <td>
                            <a href="javascript:void(0)" onclick="editlinkType(<?php echo $this->escape($linkType->typeId) ?>)">编辑</a> |
                            <a href="javascript:if(confirm('确实要删除【<?php echo $this->escape($linkType->typeName) ?>】链接类型吗?删除类型将会删除该类型下的全部链接！'))location='/backend/del/linktype/id/<?php echo $this->escape($linkType->typeId) ?>'">删除</a>
                        </td>
                    </tr>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </tbody>
                <tfoot class="ui-state-default">
                    <tr>
                        <th width="5%">ID</th>
                        <th width="20%">类型</th>
                        <th width="45%">描述</th>
                        <th width="15%">顺序</th>
                        <th width="15%">编辑</th>
                    </tr>
                </tfoot>
            </table>
            <?php if($this->linkTypeId == 0 && !empty($this->linkTypeList)) echo $this->paginationControl($this->linkTypeList,'Elastic','pagebar.phtml'); ?>
        </div>
        <div id="tabs-2" class="editor-area">
            <form action="/backend/add/linktype/" method="post" onsubmit="return submitAdd();">
                <div class="titlebox">
                    <h3><span>类型</span></h3>
                    <input type="text" class="title" id="add_type_name" name="type_name" autocomplete="off" value="" tabindex="1" size="30" />
                </div>
                <div class="titlebox">
                    <h3><span>描述</span></h3>
                    <input type="text" class="title" id="add_type_desc" name="type_desc" autocomplete="off" value="" tabindex="1" size="30" />
                </div>
                <div id="add-message-box" class="ui-state-error ui-corner-all" style="display: none;padding: 12px;">
                    <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: 12px;"></span>
                        <strong>警告:</strong> <span id="add-error-message"></span>
                    </p>
                </div>
                <div>
                    <input id="publish" type="submit" value="添加" name="publish"/>
                </div>
            </form>
        </div>
        <div id="tabs-3" class="editor-area">
            <form action="/backend/edit/linktype/" method="post" onsubmit="return submitEdit();">
                <div class="titlebox">
                    <h3><span>类型</span></h3>
                    <input type="text" class="title" id="edit_type_name" name="type_name" autocomplete="off" value="<?php echo $this->escape($this->linkTypeInfo->typeName) ?>" tabindex="1" size="30"/>
                </div>
                <div class="titlebox">
                    <h3><span>描述</span></h3>
                    <input type="text" class="title" id="edit_type_desc" name="type_desc" autocomplete="off" value="<?php echo $this->escape($this->linkTypeInfo->typeDesc) ?>" tabindex="1" size="30" />
                </div>
                <div>
                    <h3><span>排序</span></h3>
                    <input type="text" class="title" id="edit_display_order" name="display_order" autocomplete="off" value="<?php echo $this->escape($this->linkTypeInfo->displayOrder) ?>" tabindex="1" size="2" />
                </div>
                <div id="edit-message-box" class="ui-state-error ui-corner-all" style="display: none;padding: 12px;">
                    <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: 12px;"></span>
                        <strong>警告:</strong> <span id="edit-error-message"></span>
                    </p>
                </div>
                <div>
                    <input id="publish" type="submit" value="修改" name="publish"/>
                    <input id="typeId" type="hidden" value="<?php echo $this->escape($this->linkTypeInfo->typeId) ?>" name="typeId" />
                </div>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function() {
        $("#tabs").tabs({
<?php if($this->linkTypeId > 0): ?>
            disabled: [0],
<?php else: ?>
            disabled: [2],
<?php endif; ?>
            collapsible: true
        });
    });

    function submitAdd(){
        if ($("#add_type_name").val() == '') {
            $("#add-message-box").show();
            $("#add-error-message").empty();
            $("#add-error-message").append("请输入类型名称!");
            return false;
        } else if ($("#add_type_desc").val() == '') {
            $("#add-message-box").show();
            $("#add-error-message").empty();
            $("#add-error-message").append("请输入类型描述!");
            return false;
        } else {
            return true;
        }
    }


    function submitEdit(){
        if ($("#edit_type_name").val() == '') {
            $("#edit-message-box").show();
            $("#edit-error-message").empty();
            $("#edit-error-message").append("请输入类型名称!");
            return false;
        } else if ($("#edit_type_desc").val() == '') {
            $("#edit-message-box").show();
            $("#edit-error-message").empty();
            $("#edit-error-message").append("请输入类型描述!");
            return false;
        } else if ($("#edit_display_order").val() == '') {
            $("#edit-message-box").show();
            $("#edit-error-message").empty();
            $("#edit-error-message").append("请输入分类排序!");
            return false;
        } else {
            return true;
        }
    }

    function editlinkType(id){
        $("#tabs").tabs('option', 'disable', []);
        window.location.href = '/backend/list/linktype/id/'+ id + '#tabs-' + 3;
    }
</script>
</div>
<?php echo $this->render('footer.phtml'); ?>